/**蜂鸣器与LED联合使用实例**/
#define BUZZER 10   //控制蜂鸣器的数字IO脚
#define LED 9     //控制LED的数字IO脚

void setup()
{
  pinMode(BUZZER,OUTPUT);
  pinMode(LED,OUTPUT); 
  digitalWrite(LED,LOW);     //LED亮灯
  delay(1000);
}

void loop()
{
  unsigned short i,j;
  unsigned long lasttime=millis();
  digitalWrite(LED,HIGH);     //LED亮灯
  for(i = 0; i < 100; i++){
    digitalWrite(BUZZER,HIGH);//发声音
    delay(1);//延时 1ms 
    digitalWrite(BUZZER,LOW);//不发声音
    delay(1);//延时 ms 
  }
    digitalWrite(LED,LOW);     //LED熄灭
    delay(1000);
    digitalWrite(LED,HIGH);     //LED亮灯
    
  for(i=0;i<100;i++)//可以通过修改时间间隔来改变声音的频率。
  { 
    digitalWrite(BUZZER,HIGH);//发声音
    delay(3);//延时 2ms 
    digitalWrite(BUZZER,LOW);//不发声音
    delay(3);//延时 2ms 
   } 
  digitalWrite(LED,LOW);     //LED熄灭
  delay(1000);

}
